import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:fluttertoast/fluttertoast.dart';

class Message {
  static init() {
    EasyLoading.instance
      ..contentPadding =
          const EdgeInsets.symmetric(vertical: 10.5, horizontal: 20.0)
      ..indicatorWidget = const CircularProgressIndicator()
      ..userInteractions = true;
  }

  /// 显示toast
  static showToast({required String msg}) {
    EasyLoading.showToast(msg);
  }

  /// 显示loading
  static showLoading() {
    EasyLoading.show();
  }

  /// 隐藏loading
  static hideLoading() {
    EasyLoading.dismiss();
  }

  // FToat版本的toast（目前没用到）
  static showFloatToast(BuildContext context, {required String msg}) {
    // 自定义flutertoast风格
    FToast()
      ..init(context)
      ..showToast(
        child: DecoratedBox(
            decoration: BoxDecoration(
                color: Colors.black.withAlpha(200),
                borderRadius: BorderRadius.circular(3.0)),
            child: Padding(
              padding: EdgeInsets.symmetric(vertical: 10.5, horizontal: 20.0),
              child: Text(
                msg,
                style:
                    TextStyle(color: Colors.white, height: 1, fontSize: 14.0),
              ),
            )),
        gravity: ToastGravity.CENTER,
        toastDuration: Duration(seconds: 2),
      );
  }
}
